package com.kj.platformlogistics.home.adapter;

import android.graphics.Color;
import android.view.animation.LinearInterpolator;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kj.platformlogistics.R;
import com.kj.platformlogistics.home.model.SolicilationedModel;
import com.kj.platformlogistics.home.model.WaitSolicilationListModel;

import java.util.List;

import me.samlss.broccoli.Broccoli;
import me.samlss.broccoli.BroccoliGradientDrawable;
import me.samlss.broccoli.PlaceholderParameter;

public class WaitSolicilationAdapter extends BaseQuickAdapter<SolicilationedModel.ResultDTO.PageDTO, BaseViewHolder> {

    public WaitSolicilationAdapter(@Nullable List<SolicilationedModel.ResultDTO.PageDTO> data) {
        super(R.layout.item_common, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SolicilationedModel.ResultDTO.PageDTO item) {

        Broccoli broccoli = null;
        if (broccoli == null){
            broccoli = new Broccoli();
        }

        broccoli.removeAllPlaceholders();
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvOrderNumber))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvPostAddress))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvPostPhone))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvPostName))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvNumber))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.show();



        Runnable task = null;
        if (task == null){
            final Broccoli finalBroccoli = broccoli;
            task = new Runnable() {
                @Override
                public void run() {
                    //when you need to update data, you must to call the remove or the clear method.
                    finalBroccoli.removeAllPlaceholders();

                    if (item==null){
                        return;
                    }
                    helper.setText(R.id.tvOrderNumber,item.getWaybillNumber()==null?"订单号：":"订单号："+item.getWaybillNumber());
                    helper.setText(R.id.tvPostAddress,item.getMailAddress()==null?"":item.getMailAddress());
                    helper.setText(R.id.tvPostPhone,item.getMailPhone()==null?"":item.getMailPhone());
                    helper.setText(R.id.tvPostName,item.getMailName()==null?"":item.getMailName());
                    helper.setText(R.id.tvNumber,item.getNum()+"");
                }
            };
        }else{
            helper.itemView.removeCallbacks(task);
        }
        helper.itemView.postDelayed(task, 1000);
    }
}
